home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / game / shoot / ADescentSrc.lha / descent / main / joydefs.c < prev    next >
C/C++ Source or Header  |  1998-03-03  |  11KB  |  385 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: /usr/CVS/descent/main/joydefs.c,v $
  15.  * $Revision: 1.1.1.1 $
  16.  * $Author: nobody $
  17.  * $Date: 1998/03/03 15:12:25 $
  18.  * 
  19.  * .
  20.  *
  21.  * $Log: joydefs.c,v $
  22.  * Revision 1.1.1.1  1998/03/03 15:12:25  nobody
  23.  * reimport after crash from backup
  24.  *
  25.  * Revision 1.2  1998/02/28 00:38:05  hfrieden
  26.  * Modified joystick stuff for analog joysticks
  27.  *
  28.  * 
  29.  */
  30.  
  31.  
  32. #pragma off (unreferenced)
  33. static char rcsid[] = "$Id: joydefs.c,v 1.1.1.1 1998/03/03 15:12:25 nobody Exp $";
  34. #pragma on (unreferenced)
  35.  
  36. #include <stdlib.h>
  37. #include <stdio.h>
  38. #include <string.h>
  39.  
  40. #include "mono.h"
  41. #include "key.h"
  42. #include "joy.h"
  43. #include "timer.h"
  44. #include "error.h"
  45.  
  46. #include "inferno.h"
  47. #include "game.h"
  48. #include "object.h"
  49. #include "player.h"
  50.  
  51. #include "controls.h"
  52. #include "joydefs.h"
  53. #include "victor.h"
  54. #include "render.h"
  55. #include "palette.h"
  56. #include "newmenu.h"
  57. #include "args.h"
  58. #include "text.h"
  59. #include "kconfig.h"
  60. #include "digi.h"
  61. #include "playsave.h"
  62.  
  63. #include <inline/dos.h>
  64. extern void *DOSBase;
  65.  
  66. int joydefs_calibrate_flag = 0;
  67.  
  68. void joy_delay()
  69. {
  70.     stop_time();
  71.     Delay(13L);
  72.     joy_flush();
  73.     start_time();
  74. }
  75.  
  76.  
  77. int joycal_message( char * title, char * text )
  78. {
  79.     int i;
  80.     newmenu_item    m[2];
  81.     m[0].type = NM_TYPE_TEXT; m[0].text = text;
  82.     m[1].type = NM_TYPE_MENU; m[1].text = TXT_OK;
  83.     i = newmenu_do( title, NULL, 2, m, NULL );
  84.     if ( i < 0 ) 
  85.         return 1;
  86.     return 0;
  87. }
  88.  
  89. extern int WriteConfigFile();   
  90.  
  91. void joydefs_calibrate()
  92. {
  93.     ubyte masks;
  94.     int org_axis_min[4];
  95.     int org_axis_center[4];
  96.     int org_axis_max[4];
  97.  
  98.     int axis_min[4] = { 0, 0, 0, 0 };
  99.     int axis_cen[4] = { 0, 0, 0, 0 };
  100.     int axis_max[4] = { 0, 0, 0, 0 };
  101.  
  102.     int temp_values[4];
  103.     char title[50];
  104.     char text[50];
  105.     int nsticks = 0;
  106.  
  107.     joydefs_calibrate_flag = 0;
  108.  
  109.     if ( (Config_control_type!=CONTROL_JOYSTICK) && (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) && (Config_control_type!=CONTROL_THRUSTMASTER_FCS) && (Config_control_type!=CONTROL_GRAVIS_GAMEPAD) )    
  110.         return;
  111.  
  112.     joy_get_cal_vals(org_axis_min, org_axis_center, org_axis_max);
  113.  
  114.     joy_set_cen();
  115.     joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
  116.  
  117.     if (!joy_present)   {
  118.         nm_messagebox( NULL, 1, TXT_OK, TXT_NO_JOYSTICK );
  119.         return;
  120.     }
  121.     
  122.     masks = joy_get_present_mask();
  123.     if ( masks == JOY_ALL_AXIS )
  124.         nsticks = 2;
  125.     else
  126.         nsticks = 1;
  127.  
  128.     if ( nsticks == 2 ) {
  129.         sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
  130.         sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
  131.     } else {
  132.         sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
  133.         sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
  134.     }
  135.     if (joycal_message( title, text )) {
  136.         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
  137.         return;
  138.     }
  139.     joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
  140.     axis_min[0] = temp_values[0];
  141.     axis_min[1] = temp_values[1];
  142.     joy_delay();
  143.  
  144.     if ( nsticks == 2 ) {
  145.         sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
  146.         sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
  147.     } else {
  148.         sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
  149.         sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
  150.     }
  151.     if (joycal_message( title, text)) {
  152.         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
  153.         return;
  154.     }
  155.     joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
  156.     axis_max[0] = temp_values[0];
  157.     axis_max[1] = temp_values[1];
  158.     joy_delay();
  159.  
  160.     if ( nsticks == 2 ) {
  161.         sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_CENTER);
  162.         sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
  163.     } else {
  164.         sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_CENTER);
  165.         sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
  166.     }
  167.     if (joycal_message( title, text)) {
  168.         joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
  169.         return;
  170.     }
  171.     joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
  172.     axis_cen[0] = temp_values[0];
  173.     axis_cen[1] = temp_values[1];
  174.     joy_delay();
  175.  
  176.     // The fcs uses axes 3 for hat, so don't calibrate it.
  177.     if ( Config_control_type == CONTROL_THRUSTMASTER_FCS )  {
  178.         axis_min[3] = 0;
  179.         axis_cen[3] = temp_values[3]/2;
  180.         axis_max[3] = temp_values[3];
  181.         joy_delay();
  182.     } else {
  183.         masks = joy_get_present_mask();
  184.  
  185.         if ( nsticks == 2 ) {
  186.             if ( kconfig_is_axes_used(2) || kconfig_is_axes_used(3) )   {
  187.                 sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT);
  188.                 sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL);
  189.                 if (joycal_message( title, text )) {
  190.                     joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
  191.                     return;
  192.                 }
  193.                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
  194.                 axis_min[2] = temp_values[2];
  195.                 axis_min[3] = temp_values[3];
  196.                 joy_delay();
  197.  
  198.                 sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT);
  199.                 sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR);
  200.                 if (joycal_message( title, text ))  {
  201.                     joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); 
  202.                     return;
  203.                 }
  204.                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
  205.                 axis_max[2] = temp_values[2];
  206.                 axis_max[3] = temp_values[3];
  207.                 joy_delay();
  208.         
  209.                 sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_CENTER);
  210.                 sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_C);
  211.                 if (joycal_message( title, text ))  {
  212.                     joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
  213.                     return;
  214.                 }
  215.                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
  216.                 axis_cen[2] = temp_values[2];
  217.                 axis_cen[3] = temp_values[3];   
  218.                 joy_delay();
  219.             }
  220.         } else if ( (!(masks & JOY_2_X_AXIS)) && (masks & JOY_2_Y_AXIS) )   {
  221.             if ( kconfig_is_axes_used(3) )  {
  222.                 // A throttle axis!!!!!
  223.                 sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_FORWARD);
  224.                 if (joycal_message( title, TXT_MOVE_THROTTLE_F))    {
  225.                     joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
  226.                     return;
  227.                 }
  228.                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
  229.                 axis_min[3] = temp_values[3];
  230.                 joy_delay();
  231.         
  232.                 sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_REVERSE);
  233.                 if (joycal_message( title, TXT_MOVE_THROTTLE_R)) {
  234.                     joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
  235.                     return;
  236.                 }
  237.                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
  238.                 axis_max[3] = temp_values[3];
  239.                 joy_delay();
  240.         
  241.                 sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_CENTER);
  242.                 if (joycal_message( title, TXT_MOVE_THROTTLE_C)) {
  243.                     joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max);
  244.                     return;
  245.                 }
  246.                 joystick_read_raw_axis( JOY_ALL_AXIS, temp_values );
  247.                 axis_cen[3] = temp_values[3];
  248.                 joy_delay();
  249.             }
  250.         }
  251.     }
  252.     joy_set_cal_vals(axis_min, axis_cen, axis_max);
  253.  
  254.     WriteConfigFile();  
  255. }
  256.  
  257.  
  258. //char *control_text[CONTROL_MAX_TYPES] = { "Keyboard only", "Joystick", "Flightstick Pro", "Thrustmaster FCS", "Gravis Gamepad", "Mouse", "Cyberman" };
  259.  
  260. void joydef_menuset_1(int nitems, newmenu_item * items, int *last_key, int citem )
  261. {
  262.     int i;
  263.     int oc_type = Config_control_type;
  264.  
  265.     nitems = nitems;
  266.     last_key = last_key;
  267.     citem = citem;      
  268.  
  269.     for (i=0; i<CONTROL_MAX_TYPES; i++ )
  270.         if (items[i].value) Config_control_type = i;
  271.  
  272.     if ( (oc_type != Config_control_type) && (Config_control_type == CONTROL_THRUSTMASTER_FCS ) )   {
  273.         nm_messagebox( TXT_IMPORTANT_NOTE, 1, TXT_OK, TXT_FCS );
  274.     }
  275.  
  276.     if (oc_type != Config_control_type) {
  277.         switch (Config_control_type) {
  278.     //      case    CONTROL_NONE:
  279.             case    CONTROL_JOYSTICK:
  280.             case    CONTROL_FLIGHTSTICK_PRO:
  281.             case    CONTROL_THRUSTMASTER_FCS:
  282.             case    CONTROL_GRAVIS_GAMEPAD:
  283.     //      case    CONTROL_MOUSE:
  284.     //      case    CONTROL_CYBERMAN:
  285.                 joydefs_calibrate_flag = 1;
  286.         }
  287.         kc_set_controls();
  288.     }
  289.  
  290. }
  291.  
  292. extern ubyte kc_use_external_control;
  293. extern ubyte kc_enable_external_control;
  294. extern ubyte *kc_external_name;
  295.  
  296. void joydefs_config()
  297. {
  298.     char xtext[128];
  299.     int i, old_masks, masks;
  300.     newmenu_item m[13];
  301.     int i1=9;
  302.     int nitems;
  303.  
  304.     do {
  305.         nitems = 10;
  306.         m[0].type = NM_TYPE_RADIO; m[0].text = CONTROL_TEXT(0); m[0].value = 0; m[0].group = 0;
  307.         m[1].type = NM_TYPE_RADIO; m[1].text = CONTROL_TEXT(1); m[1].value = 0; m[1].group = 0;
  308.         m[2].type = NM_TYPE_RADIO; m[2].text = CONTROL_TEXT(2); m[2].value = 0; m[2].group = 0;
  309.         m[3].type = NM_TYPE_RADIO; m[3].text = CONTROL_TEXT(3); m[3].value = 0; m[3].group = 0;
  310.         m[4].type = NM_TYPE_RADIO; m[4].text = CONTROL_TEXT(4); m[4].value = 0; m[4].group = 0;
  311.         m[5].type = NM_TYPE_RADIO; m[5].text = CONTROL_TEXT(5); m[5].value = 0; m[5].group = 0;
  312.         m[6].type = NM_TYPE_RADIO; m[6].text = CONTROL_TEXT(6); m[6].value = 0; m[6].group = 0;
  313.         m[7].type = NM_TYPE_MENU; m[7].text=TXT_CUST_ABOVE;
  314.         m[8].type = NM_TYPE_TEXT; m[8].text="";
  315.         m[9].type = NM_TYPE_MENU; m[9].text=TXT_CUST_KEYBOARD;
  316.     
  317.         if ( kc_use_external_control )  {
  318.             sprintf( xtext, "Enable %s", kc_external_name );
  319.             m[10].type = NM_TYPE_CHECK; m[10].text = xtext; m[10].value = kc_enable_external_control;
  320.             nitems = nitems + 1;
  321.         }
  322.         
  323.         m[Config_control_type].value = 1;
  324.      
  325.         i1 = newmenu_do1( NULL, TXT_CONTROLS, nitems, m, joydef_menuset_1, i1 );
  326.  
  327.         switch(i1)  {
  328.         case 7: {
  329.                 old_masks = 0;
  330.                 for (i=0; i<4; i++ )        {
  331.                     if (kconfig_is_axes_used(i))
  332.                         old_masks |= (1<<i);
  333.                 }
  334.                 if ( Config_control_type==0 )
  335.                     // nothing...
  336.                     Config_control_type=0;
  337.                 else if ( Config_control_type<5 ) 
  338.                     kconfig(1, CONTROL_TEXT(Config_control_type) ); 
  339.                 else 
  340.                     kconfig(2, CONTROL_TEXT(Config_control_type) ); 
  341.  
  342.                 masks = 0;
  343.                 for (i=0; i<4; i++ )        {
  344.                     if (kconfig_is_axes_used(i))
  345.                         masks |= (1<<i);
  346.                 }
  347.  
  348.                 switch (Config_control_type) {
  349.                 case    CONTROL_JOYSTICK:
  350.                 case    CONTROL_FLIGHTSTICK_PRO:
  351.                 case    CONTROL_THRUSTMASTER_FCS:   
  352.                     {
  353.                         for (i=0; i<4; i++ )    {
  354.                             if ( (masks&(1<<i)) && (!(old_masks&(1<<i))))
  355.                                 joydefs_calibrate_flag = 1;
  356.                         }
  357.                     }
  358.                     break;
  359.                 }
  360.             }
  361.             break;
  362.         case 9: 
  363.             kconfig(0, TXT_KEYBOARD); 
  364.             break;
  365.         } 
  366.  
  367.         if ( kc_use_external_control )  {
  368.             kc_enable_external_control = m[10].value;
  369.         }
  370.  
  371.     } while(i1>-1);
  372.  
  373.     switch (Config_control_type) {
  374.     case    CONTROL_JOYSTICK:
  375.     case    CONTROL_FLIGHTSTICK_PRO:
  376.     case    CONTROL_THRUSTMASTER_FCS:
  377.     case    CONTROL_GRAVIS_GAMEPAD:
  378.         if ( joydefs_calibrate_flag )
  379.             joydefs_calibrate();
  380.         break;
  381.     }
  382.  
  383. }
  384.  
  385.